#include <stdio.h>
#include <stdlib.h>
#define D(s) s=p[e++]-48;while(p[e]!=32&&p[e])s=10*s+p[e++]-48;e++;
#define uint unsigned int
void main()
{
	char p[10000];
	uint e=0,max1=0,max2=0,i,j,n,*v,M1=0,M2=0;
	gets(p);D(n)e=0;gets(p);
	v=(uint*)malloc(n*sizeof(uint));
	for (i=0;i<n;i++)
	{
		D(v[i])
	}
	if(n==1)max1=max2=v[0];
	for (i=0;i<n-1;i++)
	{
		v[i]>max1?max1=v[i]:v[i]>max2?max2=v[i]:0;
		for (j=i+1;j<n;j++)
		{
			if ((v[j]^max1)>max1)
			{
				max2=max1;
				max1^=v[j];
			}else if(v[j]^max1>max2)
				max2=v[j]^max1;
		}
		if (max1>M1)
		{
			M1=max1;
			if (max2>M2)
			{
				M2=max2;
			}
		}else if(max1>M2)
		{
			M2=max1;
		}
		max1=max2=0;
	}
	v[i]>M1?M1=v[i]:v[i]>M2?M2=v[i]:0;
	free(v);
	printf("%d %d",M1,M2);
}